# coding=utf-8

from datetime import datetime
import re


class Info:

    def __init__(self):
        self.count = 0
        self.detail = []

    def __str__(self):
        ret = "%s" % (self.count)
        for str1 in self.detail:
            ret += ("\n    %s" % str1)
        ret += "\n"
        return ret 

    
def p(str1):
    if 0:
        print("%s" % str1)

    
if __name__ == '__main__':

    # 1.读文件
    with open('7000.txt', 'r', encoding='UTF-8') as f:
        lines = f.readlines()
    
    # 转成字典
    dict1 = dict()

    print(datetime.now())
    
    for line in lines:
        strs = list(filter(None, re.split(r'[\s\t\(\):=]', line[31:], maxsplit=0)))
#         strs = line[31:].split(str=" :", num=3)
        if strs == []:
            continue
        
        len1 = len(strs)
        
        if len1 >= 3:
            key = (strs[0], strs[1], strs[2])
        elif len1 == 2:
            key = (strs[0], strs[1])
        else:
            key = (strs[0])
    
        if key in dict1:
            value = dict1[key]
        else:
            value = Info()
            dict1[key] = value
        
        value.detail.append(line)
        value.count += 1
     
    print(datetime.now())
    
    result = sorted(dict1.items(), key=lambda x:x[1].count, reverse=True)
    
    print(datetime.now())
    
    # 6.校验总和
    sum1 = 0;
    for info in result:
        print(info[0])
        print(info[1])
        sum1 += info[1].count
    print("info: sum=%s" % sum1)
        
    print("*** OVER ***")

